#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main()
{
    int n,m,a,b;
    while(cin>>n>>m>>a>>b)
    {
        int ans = 0;
        int t = (a-1)%m;
        if(t) ans++,t=a+(m-t);
        else t=a;
        if(t<=b)
        {
            if((b-t+1)/m||b==n) ans++;
            if(b!=n&&(b-t+1)%m) ans++;
            if((b-t+1)/m&&(b-1)%m+1==(a-1)%m) ans--;
        }
        cout<<ans<<endl;
    }
	return 0;
}
